<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2020/1/15
  Time: 11:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <script src="js/jquery.min.js"></script>

    <script>
        $(function () {
            $("#btn1").click(function () {
                // alert("我被点击啦")
                $.ajax({
                    url: "user/anno/return/testAjax1",
                    data: '{"name":"heihei","age":1024}',
                    contentType: "application/json;charset=UTF-8",//请求json格式

                    dataType: "json",//响应json格式
                    type: "post",
                    success: function (data) {
                        console.debug(data);
                        alert(data.name + "------" + data.age);
                    }
                });
            });
            $("#btn2").click(function () {
                // alert("我被点击啦")
                $.ajax({
                    url: "user/anno/return/testAjax2",
                    contentType: "application/x-www-form-urlencoded",//请求表单格式
                    data: 'name=heihei&age=1024',

                    dataType: "json",//响应json格式
                    type: "post",
                    success: function (data) {
                        console.debug(data);
                        alert(data.name + "------" + data.age);
                    }
                });
            });
        });
    </script>

</head>
<body>
<button id="btn1">发送ajax的json请求</button>
<button id="btn2">发送ajax的表单请求</button>
</body>
</html>
